//
//  ThemeViewController.m
//  A段项目音乐播放
//
//  Created by dllo on 15/5/22.
//  Copyright (c) 2015年 lanou3g.com蓝鸥科技. All rights reserved.
//

#import "ThemeViewController.h"

@interface ThemeViewController ()<UIScrollViewDelegate>
@property (nonatomic,retain)UIView *viewSmall;
@property (nonatomic,retain)UIScrollView *scroll;

@end

@implementation ThemeViewController

- (void)dealloc
{
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self createScroll];

}



// 创建 scrollview
- (void)createScroll
{
    UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)];
    
    self.scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 30, self.view.frame.size.width, self.view.frame.size.height - 200)];
    self.scroll.contentSize = CGSizeMake(self.view.frame.size.width * 3, 0);
    self.scroll.contentOffset = CGPointMake(self.view.frame.size.width, 0);
    //    self.scroll.backgroundColor = [UIColor greenColor];
    self.scroll.pagingEnabled = YES;
    self.scroll.delegate = self;
    [self.view addSubview:self.scroll];
    
    NSArray *array = @[@"推荐",@"分类",@"我的"];
    for (int i = 0; i < [array count]; i ++) {
        NSString *str = [array objectAtIndex:i];
        
        UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width / 3 * i, 0, self.view.frame.size.width / 3, 28)];
        [button setTitle:str forState:UIControlStateNormal];
        [button setTitleColor:[UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.5] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
        [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        button.tag = i + 1;
        [topView addSubview:button];
    }
    
    self.viewSmall = [[UIView alloc]initWithFrame:CGRectMake(0, 28, self.view.frame.size.width / 3, 2)];
    self.viewSmall.backgroundColor = [UIColor blueColor];
    
    [topView addSubview:self.viewSmall];
    [self.view addSubview:topView];
    
}

- (void)createImageView
{
    UIImageView *image0 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    
//    NSString *name = [ns]
    
}

- (UIImage *)imageWithName:(NSString *)name type:(NSString *)type
{
    NSString *path = [[NSBundle mainBundle]pathForResource:name ofType:type];
    UIImage *image = [UIImage imageWithContentsOfFile:path];
    return image;
}



// button 的点击事件
- (void)buttonAction:(id)sender
{
    
    UIButton *button = (UIButton *)sender;
    self.scroll.contentOffset = CGPointMake((button.tag - 1) * [UIScreen mainScreen].bounds.size.width, 0);
    [UIView animateWithDuration:0.1 animations:^{
        [self.viewSmall setFrame:CGRectMake((self.view.frame.size.width / 3) * (button.tag - 1), 28, self.view.frame.size.width / 3, 2)];
    }];
    
}


// scrollview 的 彻底停止 协议

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    // 结束 减速
    
    [UIView animateWithDuration:0.05 animations:^{
        [self.viewSmall setFrame:CGRectMake((self.view.frame.size.width / 3) * (self.scroll.contentOffset.x / self.view.frame.size.width) , 28, (self.view.frame.size.width / 3), 2)];
    }];
    
}


// 点击空白处  收回键盘
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}














- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
